Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect string comparisons against segfaults #547

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JSydll
Copy link

@JSydll JSydll commented Dec 3, 2024

This intends to resolve #546.

Comparing string objects to nullptr is not prevented by the implementation. Therefore, it should check before starting the actual comparison - which currently leads to a segfault due to the unprotected use of CharStrlen. Given that CharStrlen fulfills the standard specification of showing UB when called like that, the issue should be fixed on the calling site.

The first commit introduces minimal test cases for the global equality operators for basic_string, the second the (quite small) fix.

@virt00l
Copy link
Contributor

virt00l commented Feb 4, 2025

Im pretty sure that's intentionaly for perfomance sake
strlen("foo", NULL) would also segfault (I assuming for the same reason)

@JSydll
Copy link
Author

JSydll commented Feb 4, 2025

I do acknowledge that strlen (or the EASTL variant of it, CharStrlen) may segfault, as this is allowed by the specification. What is far less obvious to me is the described use of comparison operators. The current behavior is especially brittle in template contexts.

Do you have an indication on performance impact in this use case? And maybe a recommendation on an alternative solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

string.h: Missing nullptr handling in operator== leading to segfaults
2 participants